# Definition for a binary tree node.
class TreeNode(object):
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
        
        
class Solution(object):
    def minDepth(self, root:TreeNode)->int:
        """
        :type root: TreeNode
        :rtype: int
        """
        
        if root==None:
            return 0
        minDepth:int=0;
        if root.left!=None:
            minDepth=self.minDepth(root.left)
        if root.right!=None:
            if minDepth==0:
                minDepth=self.minDepth(root.right)
            else:
                minDepth=min([self.minDepth(root.right),minDepth])
            
        return 1+minDepth